using System;
using System.Collections.Generic;
using System.Text;
using Deepcode.Flux.Core.Services.Configuration;

namespace Deepcode.Flux.Core.Services.MailHandlers
{
	public class SimpleMail : IMailHandler
	{
		/// <summary>
		/// Send the email using System.Net.Mail
		/// Will not work with certain SMTP-AUTH servers
		/// </summary>
		/// <param name="mm"></param>
		/// <param name="ServerAddress"></param>
		/// <param name="ServerPort"></param>
		public void SendMail(StandardMailMessage mm)
		{
			System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage();
			m.From = new System.Net.Mail.MailAddress( mm.From );
			m.To.Add( mm.To );
			if( mm.CC != "" ) m.CC.Add( mm.CC );
			if( mm.BCC != "" ) m.Bcc.Add( mm.BCC );
			m.Subject = mm.Subject;
			m.Body = mm.Body;
			m.IsBodyHtml = mm.BodyIsHtml;

			System.Net.Mail.SmtpClient c = new System.Net.Mail.SmtpClient( FluxConfig.MailServer );
			if( FluxConfig.MailUsername != "" )
			{
				System.Net.NetworkCredential nc = 
					new System.Net.NetworkCredential( FluxConfig.MailUsername, FluxConfig.MailPassword );

				c.Credentials = nc;
			}

			c.Send( m );
		}
	}
}
